//
//  FindKnowlegeView.m
//  0000327App
//
//  Created by user on 16/3/29.
//  Copyright © 2016年 MoreMoney. All rights reserved.
//
#import "FindModel.h"
#import "FindKnowlegeView.h"
#import "FindKonwlegeCell.h"

@interface FindKnowlegeView () <UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) NSArray *models;

@end

@implementation FindKnowlegeView
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super initWithCoder:aDecoder]) {
        [self setup];
    }
    return self;
}
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
    if (self = [super initWithFrame:frame style:style]) {

        [self setup];
    }
    return self;
}


- (void)setup
{
    self.dataSource = self;
    self.delegate = self;
    UINib *nib = [UINib nibWithNibName:@"FindKonwlegeCell" bundle:nil];
    [self registerNib:nib forCellReuseIdentifier:@"findcell"];
    self.backgroundColor = [UIColor colorWithRed:231/255.0 green:231/255.0 blue:231/255.0 alpha:1];
    
    self.contentInset = UIEdgeInsetsMake(20, 0, 60, 0);
    self.contentOffset = CGPointMake(0, -20);
}

#pragma mark - ======== data source ========
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.models.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    FindModel *model = self.models[indexPath.row];
    
    FindKonwlegeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"findcell" forIndexPath:indexPath];
    
    cell.model = model;
    
    return cell;
}

#pragma mark - ======== 代理 ========
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    FindKonwlegeCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"FindKonwlegeCell" owner:nil options:nil] lastObject];
    
    return cell.bounds.size.height;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%s",__func__);
}

#pragma mark - ======== 懒加载 ========
- (NSArray *)models
{
    if (!_models) {
        
        _models = [FindModel models];
    }
    return _models;
}
@end
